import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [{
		path: '/login',
		component: () =>
			import('@/views/login/index'),
		hidden: true
	},
	{
		path: '/404',
		component: () =>
			import('@/views/404'),
		hidden: true
	},

	{
		path: '/dashboard',
		component: Layout,
		name: 'Dashboard',
		hidden: true,
		children: [{
			path: '',
			component: () =>
				import('@/views/dashboard/index')
		}]
	},
	{
		path: '/example',
		component: Layout,
		redirect: '/example/table',
		name: 'Example',
		meta: {
			title: '案例',
			icon: 'noicon'
		},
		children: [{
				path: 'table',
				name: 'Table',
				component: () =>
					import('@/views/table/index'),
				meta: {
					title: '表格',
					icon: 'noicon'
				}
			},
			{
				path: 'tree',
				name: 'Tree',
				component: () =>
					import('@/views/tree/index'),
				meta: {
					title: '树形结构',
					icon: 'noicon'
				}
			}
		]
	},
	{
		path: '/charts',
		component: Layout,
		redirect: 'noredirect',
		name: 'charts',
		meta: {
			title: '图表',
			icon: 'noicon'
		},
		children: [{
				path: 'keyboard',
				component: () =>
					import('@/views/charts/keyboard'),
				name: 'keyboardChart',
				meta: {
					title: '键盘图表',
					icon: 'noicon'
				}
			},
			{
				path: 'line',
				component: () =>
					import('@/views/charts/line'),
				name: 'lineChart',
				meta: {
					title: '折线图',
					icon: 'noicon'
				}
			},
			{
				path: 'mixchart',
				component: () =>
					import('@/views/charts/mixChart'),
				name: 'mixChart',
				meta: {
					title: '混合图表',
					icon: 'noicon'
				}
			}
		]
	},
	{
		path: '/form',
		component: Layout,
		children: [{
			path: 'index',
			name: 'Form',
			component: () =>
				import('@/views/form/index'),
			meta: {
				title: '表单',
				icon: 'noicon'
			}
		}]
	},

	{
		path: '/nested',
		component: Layout,
		redirect: '/nested/menu1',
		name: 'Nested',
		meta: {
			title: '菜单',
			icon: 'noicon'
		},
		children: [{
				path: 'menu1',
				component: () =>
					import('@/views/nested/menu1/index'), // Parent router-view
				name: 'Menu1',
				meta: {
					title: '菜单1',
					icon: 'noicon'
				},
				children: [{
						path: 'menu1-1',
						component: () =>
							import('@/views/nested/menu1/menu1-1'),
						name: 'Menu1-1',
						meta: {
							title: '1级',
							icon: 'noicon'
						}
					},
					{
						path: 'menu1-2',
						component: () =>
							import('@/views/nested/menu1/menu1-2'),
						name: 'Menu1-2',
						meta: {
							title: '2级',
							icon: 'noicon'
						},
						children: [{
								path: 'menu1-2-1',
								component: () =>
									import('@/views/nested/menu1/menu1-2/menu1-2-1'),
								name: 'Menu1-2-1',
								meta: {
									title: '2级首页'
								}
							},
							{
								path: 'menu1-2-2',
								component: () =>
									import('@/views/nested/menu1/menu1-2/menu1-2-2'),
								name: 'Menu1-2-2',
								meta: {
									title: '2级其他'
								}
							}
						]
					},
					{
						path: 'menu1-3',
						component: () =>
							import('@/views/nested/menu1/menu1-3'),
						name: 'Menu1-3',
						meta: {
							title: '3级',
							icon: 'noicon'
						}
					}
				]
			},
			{
				path: 'menu2',
				component: () =>
					import('@/views/nested/menu2/index'),
				meta: {
					title: '菜单2',
					icon: 'noicon'
				}
			}
		]
	},
	{
		path: '/trans',
		component: Layout,
		children: [{
			path: 'index',
			name: 'Trans',
			component: () =>
				import('@/views/trans/index'),
			meta: {
				title: '穿梭框',
				icon: 'noicon'
			}
		}]
	},
	{
		path: '/message',
		component: Layout,
		children: [{
			path: 'index',
			name: 'Message',
			component: () =>
				import('@/views/message/index'),
			meta: {
				title: '消息',
				icon: 'noicon'
			}
		}]
	},
	{
		path: '/notice',
		component: Layout,
		children: [{
			path: 'index',
			name: 'Notice',
			component: () =>
				import('@/views/notice/index'),
			meta: {
				title: '通知',
				icon: 'noicon'
			}
		}]
	},
	{
		path: '/alert',
		component: Layout,
		children: [{
			path: 'index',
			name: 'Alert',
			component: () =>
				import('@/views/alert/index'),
			meta: {
				title: '弹框',
				icon: 'noicon'
			}
		}]
	},
	{
		path: '/pagin',
		component: Layout,
		children: [{
			path: 'index',
			name: 'Pagin',
			component: () =>
				import('@/views/pagin/index'),
			meta: {
				title: '分页',
				icon: 'noicon'
			}
		}]
	},
	{
		path: '/popover',
		component: Layout,
		children: [{
			path: 'index',
			name: 'Popover',
			component: () =>
				import('@/views/popover/index'),
			meta: {
				title: '弹出框',
				icon: 'noicon'
			}
		}]
	},
	{
		path: '/axios',
		component: Layout,
		children: [{
			path: 'index',
			name: 'Axios',
			component: () =>
				import('@/views/axios/index'),
			meta: {
				title: '数据列表',
				icon: 'noicon'
			}
		}]
	},
	{
		path: 'external-link',
		component: Layout,
		children: [{
			path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
			meta: {
				title: '打开网页',
				icon: 'noicon'
			}
		}]
	},

	{
		path: '*',
		redirect: '/login',
		hidden: true
	}
]

export default new Router({
	// mode: 'history', //后端支持可开
	scrollBehavior: () => ({
		y: 0
	}),
	routes: constantRouterMap
})